 ///
 /// @file    iterator.h
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-17 14:39:43
 ///

#ifndef __MY_ITERATOR_H__
#define __MY_ITERATOR_H__
//#include <iostream>

typedef int Data;


class Iterator;

class Aggregate
{
public:
	virtual Iterator * createIterator()=0;
	virtual ~Aggregate(){}
	
	virtual int size()=0;
	virtual Data getItem(int idx)=0;
};


class Iterator
{
public:
	virtual ~Iterator(){}
	virtual void first()=0;
	virtual void next()=0;
	virtual bool isDone()=0;
	virtual Data currentItem()=0;
};



class ConcreateAggregate : public Aggregate
{
public:
	ConcreateAggregate(int size);
	virtual Iterator * createIterator();
	virtual ~ConcreateAggregate();
	
	virtual int size();
	virtual Data getItem(int idx);
private:
	int _size;
	Data * _pData;
};


class ConcreateIterator : public Iterator
{
public:
	ConcreateIterator(Aggregate * pAggregate);
	virtual ~ConcreateIterator(){}
	virtual void first();
	virtual void next();
	virtual bool isDone();
	virtual Data currentItem();
private:
	int _idx;
	Aggregate * _pAggregate;
};



#endif
